<?php

namespace App\Http\Controllers\Admin;

use App\Models\Index\LiveVideo;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LiveVideoController extends Controller
{
    public function getVideoList(Request $request)
    {
        $search = trim($request->input('search',''));
        $data   = LiveVideo::getVideoList($search);
        return self::response($data,200);
    }

    /**
     * 新增/修改 配置
     * @param Request $request
     * @return mixed
     */
    public function modifyVideo(Request $request)
    {
        $input = $request->all();

        if (empty($input['title'])) {
            return self::response(null,'-1','banner_title is null');
        }

        if (empty($input['attribute'])) {
            return self::response(null,'-1','banner_attribute is null');
        }

        if (empty($input['id'])) {
            return self::response(null,'-1','id is null');
        }

        $flag = LiveVideo::query()->where('id',$input['id'])->update(['title'=>$input['title'],'attribute'=>$input['attribute']]);

        if ($flag){
            return self::response(null,200,'修改成功');
        }else{
            return self::response(null,-1,'修改失败');
        }
    }

    public function check(Request $request)
    {
        $id     = (int)$request->input('id');
        $status = (int)$request->input('status');
        if (empty($id)) {
            return self::response(null,'-1','id is null');
        }
        if (empty($status)) {
            return self::response(null,'-1','status is null');
        }
        $flag = LiveVideo::query()->where('id','=',$id)->update(['status'=>$status]);
        if ($flag) {
            return self::response(null,200,'修改成功');
        } else {
            return self::response(null,-1,'修改失败');
        }
    }

    public function del(Request $request)
    {
        $input = $request->all();
        if (empty($input['id'])){
            return self::response(null,'-1','请选择删除项');
        }
        $flag = LiveVideo::query()->where('id',$input['id'])->delete();
        if ($flag){
            return self::response(null,200,'删除成功');
        }else{
            return self::response(null,-1,'删除失败');
        }
    }
}
